package com.base.social.auth.factory;

import com.base.social.auth.request.AuthQQ;
import com.base.social.cache.AuthStateCache;
import com.base.social.config.AuthConfig;
import com.base.social.auth.Auth;
import com.base.social.auth.AuthFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

public class QQAuthFactory implements AuthFactory {

    /**
     * 客户端id：对应各平台的appKey
     */
    private String clientId;

    /**
     * 客户端Secret：对应各平台的appSecret
     */
    private String clientSecret;

    /**
     * 登录成功后的回调地址
     */
    private String redirectUri;

    /**
     * 微信响应类型 默认code
     */
    private String responseType;

    /**
     * 微信授权作用域
     */
    private String scope;

    private AuthStateCache authStateCache;

    private static class Holder{
        private static final QQAuthFactory INSTANCE = new QQAuthFactory();
    }

    //实例化
    public static QQAuthFactory build(){
        return Holder.INSTANCE;
    }

    @Override
    public Auth instance(AuthConfig authConfig,AuthStateCache authStateCache) {
        authConfig.setClientSecret(this.clientSecret);
        authConfig.setClientId(this.clientId);
        authConfig.setRedirectUri(this.redirectUri);
        authConfig.setResponseType(this.responseType);
        authConfig.setScope(scope);
        if (authStateCache != null) {
            return new AuthQQ(authConfig, authStateCache);
        }
        return new AuthQQ(authConfig);
    }

    public String getClientId() {
        return clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public String getRedirectUri() {
        return redirectUri;
    }

    public String getResponseType() {
        return responseType;
    }

    public String getScope() {
        return scope;
    }

    public AuthStateCache getAuthStateCache() {
        return authStateCache;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public void setRedirectUri(String redirectUri) {
        this.redirectUri = redirectUri;
    }

    public void setResponseType(String responseType) {
        this.responseType = responseType;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public void setAuthStateCache(AuthStateCache authStateCache) {
        this.authStateCache = authStateCache;
    }
}
